package cn.icanci.test.controller;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;

import cn.icanci.test.service.WelcomeService;

/**
 * @author icanci
 * @date Created in 2021/02/06 23:42
 * @version 1.0
 */
@Controller
public class WelcomeController implements ApplicationContextAware, BeanNameAware {
    private String             myName;
    private ApplicationContext applicationContext;

    @Autowired
    private WelcomeService welcomeService;

    public void sayHi() {
        welcomeService.sayHi();
        System.out.println("我是 " + myName);
        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println("我将召唤出 " + beanDefinitionName);
        }
    }

    @Override
    public void setBeanName(String name) {
        this.myName = name;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
